// pages/index/forgetPassWord/forgetPassWord.js

var app = getApp()

Page({
  data: {
  	phone:'',
  	verification:'',
  	sendVer:'获取验证码',
    num:''
  },
  onLoad: function (options) {

  },
  sureVerification(){
  	if (this.data.phone=='') {
  		app.errorMsg('请输入手机号')
  	}else if (this.data.verification=='') {
  		app.errorMsg('请输入验证码')
  	}else{
	  	let data = {
	  		phone:this.data.phone,
	  		code:this.data.verification
	  	}
	  	app.request('wx_app/agent_account/checkCode',data,'GET').then(res=>{
	  		console.log(res)
	  		if (res.code==1) {
	  			wx.navigateTo({
      				url: '../register/setPassword?regAccountId='+res.data.id+'&type=0',
    			})
	  		}else{
	  			app.errorMsg(res.message)
	  		}
	  	})
  	}

  },
  //获取input内容
  getPhone(e){
  	this.setData({
  		phone:e.detail.value
  	})
  },
  getVer(e){
  	this.setData({
  		verification:e.detail.value
  	})
  },
    //发送验证码
  sendVer(){
  	console.log(321)
    if (this.data.sendVer==='获取验证码') {
      if (this.data.phone=='') {
        app.errorMsg('请输入手机号')
      }else{
        let data = {
          phoneNum:this.data.phone
        }
        console.log(data)
        app.request('wx_app/sendSmsCode',data,'GET').then(res=>{
          console.log(res)
          if (res.code==0) {
            app.errorMsg(res.message)
          }
        })
        this.setData({
          num:120,
          sendVer:'120s后重新发送'
        })
        let time = setInterval(()=>{
          let num = this.data.num
          num --
          this.setData({
            num,
            sendVer:num+'s后重新发送'
          })

          if(num == 0){
           clearInterval(time)
           this.setData({
            sendVer:'发送验证码'
          })
         }
       },1000)
      }
    }else{

    }
  }
})
